﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Input;

namespace YourLastOptionsDialog.Core.Attributes
{
    /// <summary>
    /// An option attribute that represents a string option.
    /// </summary>
    [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "I'm explicitly defining an attribute hierarchy.")]
    [AttributeUsage(AttributeTargets.Property)]
    public class OptionStringAttribute : OptionAttribute
    {
        private int _maxLength = int.MaxValue;

        /// <summary>
        /// Gets or sets the minimum allowed length of the string.
        /// The default is zero.
        /// </summary>
        public int MinLength
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the maximum allowed length of the string.
        /// The default is <see cref="int.MaxValue"/>.
        /// </summary>
        public int MaxLength
        {
            get
            {
                return _maxLength;
            }

            set
            {
                _maxLength = value;
            }
        }

        /// <summary>
        /// Gets or sets the input scope name value that is used by the UI to display a suitable SIP keyboard layout to the user.
        /// </summary>
        public InputScopeNameValue InputScopeNameValue
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a regular expression that is used to validate the string entered by the user.
        /// </summary>
        public string RegularExpression
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the type of validator to use for validation. If a validator is 
        /// specified, then none of the other validation properties are in effect anymore. In particular,
        /// if a validator is configured, the values of <see cref="MinLength"/>, <see cref="MaxLength"/>,
        /// <see cref="RegularExpression"/> and <see cref="ValidationErrorMessage"/> are ignored and the 
        /// validator is instead used for all validation.
        /// </summary>
        public Type ValidatorType
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the validation error message that is used if the value is outside the configured 
        /// minimum or maximum length, or if the value does not satisfy the given regular expression.
        /// </summary>
        public string ValidationErrorMessage
        {
            get;
            set;
        }
    }
}